import { createRouter, createWebHistory, RouteRecordRaw } from 'vue-router'
import Layout from '@/layouts/index.vue'
import Dashboard from '@/views/dashboard/index.vue'
import pagesRouter from './modules/pages'
import componentsRouter from './modules/components'

const dashboardRouter = {
  path: '/dashboard',
  name: 'Dashboard',
  component: Dashboard,
  meta: { title: '首页', icon: 'el-icon-data-analysis' }
}

export const routes: Array<RouteRecordRaw> = [
  {
    path: '/redirect',
    component: Layout,
    meta: { hidden: true, noCache: true },
    children: [
      {
        path: '/redirect/:path(.*)',
        component: () => import('@/views/redirect/index.vue')
      }
    ]
  },
  {
    path: '/',
    component: Layout,
    redirect: '/dashboard',
    children: [dashboardRouter]
  },
  pagesRouter,
  componentsRouter,
  {
    path: '/:pathMatch(.*)*',
    name: 'NotFound',
    component: () => import('@/views/error-page/404.vue'),
    meta: { noCache: true }
  }
]

export const asyncRoutes: Array<RouteRecordRaw> = [dashboardRouter, pagesRouter, componentsRouter]

const router = createRouter({
  history: createWebHistory(),
  routes,
  scrollBehavior() {
    return { top: 0 }
  }
})

export default router
